package io.renren.modules.gengyun.controller;

import com.sun.xml.internal.ws.api.ha.StickyFeature;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.gengyun.entity.Date_Api;
import io.renren.modules.gengyun.service.GatherTimeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("collectPlan")
public class PlanController {
    @Autowired
    private GatherTimeService gatherTimeService;

    @RequestMapping(value = "allPlanTarget",method = RequestMethod.POST)
//    @RequiresPermissions("gengyun:gatherTime:list")
    public R allPlanTarget(@RequestParam Map<String, Object> params){
        String date = (String) params.get("date");

//        HashMap<String, String> submitTime = Date_Api.initPlanData(date);
//
//        assert submitTime != null;
//        String beginTime = submitTime.get("beginTime");
//        String endTime = submitTime.get("endTime");

        String submitTime = Date_Api.initPlanData(date);

        List<String> targetByTime = gatherTimeService.getGatherTime(submitTime);

        List<Map<String,String>> returnTarget = new ArrayList<>();
        for (String s: targetByTime){
//            returnTarget.add((Map<String, String>) new HashMap<String, String>().put("target",s));
            Map<String,String> map = new HashMap<>();
            map.put("target",s);
            returnTarget.add(map);
        }


        return R.ok().put("allPlanTarget", returnTarget);
    }


//    @RequestMapping(value = "planTargetDetails",method = RequestMethod.POST)
////    @RequiresPermissions("gengyun:gatherTime:list")
//    public R targetDetails(@RequestParam Map<String, Object> params){
//        String target = (String) params.get("target");
//
//        return R.ok().put("allPlanTarget", returnTarget);
//    }


}
